// pages/housePushList/housePushList.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    housePushList:'',
    count:"",
    page:1,
    limit:5,
    city:'',
    houseTypeId:'',
    areaInfo:'',
    houseMoldingId:"",
    search:'',
    houseWay:'2'
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
     this.houseAddressInfo()
  },
  /**
   * 下拉加载
   */
  onReachBottom(){
    var page=this.data.page +1
    var count=this.data.count
    var limit=this.data.limit
    if((page-1)*limit>=count){
        wx.showToast({
          title:'没有数据了',
          icon:"error"
        })
        return false
    };
    wx.request({
      url: 'http://www.house.com/index.php/api/housePushList',
      data:{
        page,
        houseTypeId:this.data.houseTypeId,
        city:this.data.city,
        houseMoldingId:this.data.houseMoldingId,
        areaInfo:this.data. areaInfo,
        houseWay:this.data.houseWay
      },
      method:"GET",
      success:res=>{
        var newList=res.data.data.data
        var oldList=this.data.housePushList
        var housePushList=oldList.concat(newList)
        this.setData({
          housePushList:housePushList,
          page
        })
      }
    })
  },
  /**
   * 设置省级
   */
  address(){
      wx.navigateTo({
        url: '/pages/addressInfo/addressInfo',
      })
  },
  /**
   * 展示省级渲染
   */
  onShow(){
    this.houseAddressInfo()
  },
  /**
   * 房源类型
   */
  houseType(e){
    var houseTypeId=e.currentTarget.dataset.housetype
    this.setData({
      housePushList:'',
      houseTypeId:houseTypeId
    })
    this.houseAddressInfo()

  },
  /**
   * tab选择
   */
  changeTabs(e){
      var tab=e.detail.activeKey
      if(tab=='one'){
        wx.navigateTo({
          url: '/pages/tabArea/tabArea',
        })
      }else{
        wx.navigateTo({
          url: '/pages/tabMolding/tabMolding',
        })
      }
  },

  /**
   * 搜索
   */
  searchName(e){
     var search= e.detail.value
     this.setData({
       search
     })
    this.houseAddressInfo()
   

  },

  /**
   * 封装方法
   */
  houseAddressInfo(){
    let city = wx.getStorageSync('city')
    var areaInfo = wx.getStorageSync('area')
    var houseMoldingId = wx.getStorageSync('houseMoldingId')
    if(city==''){
      this.setData({
        city:'上海市'
      })
    }else{
      this.setData({
        city
      })
    }
      wx.request({
        url: 'http://www.house.com/index.php/api/housePushList',
        data:{
          houseTypeId:this.data.houseTypeId,
          city:this.data.city,
          areaInfo,
          houseMoldingId,
          search:this.data.search,
          houseWay:this.data.houseWay
        },
        method:"GET",
        success:res=>{
         if(res.data.code==200){
           console.log(res.data.data.houseList)
          this.setData({
            housePushList:res.data.data.houseList,
            count:res.data.data.count
          })
         }else{
           wx.showToast({
             title: res.data.msg,
             icon:"error"
           })
           this.setData({
            housePushList:'', 
          })
          return 
         }
        }
      })
  }
  

  
})